package ru.housewife.controllers;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import ru.common.hibernate.HibernateActionExecutor;
import ru.housewife.cache.CacheManager;
import ru.housewife.form.RegionForm;

import java.util.List;

/**
 * Controller to work with regions
 *
 * @author Alexander Troshanin
 */
@Controller
public class RegionsController extends AbstractController {

    private final HibernateActionExecutor hiber;

    public RegionsController(@Qualifier("houseWifesHibernate") HibernateActionExecutor hiber) {
        this.hiber = hiber;
    }

    @RequestMapping(value = "/get-select-region-form.html")
    public ModelAndView getSelectRegionForm() {
        List<RegionForm> regions = CacheManager.getInstance().getFirstLevelRegions();
        ModelAndView mv = new ModelAndView("housewifes/regions/selectRegionDialog-json-reply");
        mv.addObject("regions", regions);
        return mv;
    }

}
